local ma__zhafu = fk.CreateSkill {
  name = "ma__zhafu",
}

Fk:loadTranslationTable{
  ["ma__zhafu"] = "札符",
  [":ma__zhafu"] = "当有牌进入弃牌堆被销毁时，你可以摸一张牌。",

  ["$ma__zhafu1"] = "以符为根，以消为法。",
  ["$ma__zhafu2"] = "扎符点术，解脱之道。",
}

ma__zhafu:addEffect(fk.BeforeCardsMove, {
  can_refresh = function (self, event, target, player, data)
    return player:hasSkill(ma__zhafu.name, true)
  end,
  on_refresh = function (self, event, target, player, data)
    local cid = {}
    for _, move in ipairs(data) do
      if move.toArea == Card.DiscardPile then
        for _, info in ipairs(move.moveInfo) do
          local card = Fk:getCardById(info.cardId)
          if card:getMark(MarkEnum.DestructIntoDiscard) ~= 0 then
            table.insert(cid, card)
          end
        end
      end
    end
    player.room:setPlayerMark(player, ma__zhafu.name, cid)
  end,
})

ma__zhafu:addEffect(fk.AfterCardsMove, {
  anim_type = "drawcard",
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(ma__zhafu.name) then
      local mark = player:getMark(ma__zhafu.name)
      for _, move in ipairs(data) do
        if move.toArea == Card.Void then
          for _, info in ipairs(move.moveInfo) do
            local card = Fk:getCardById(info.cardId)
            if table.contains(mark, card) then
              return true
            end
          end
        end
      end
      player.room:setPlayerMark(player, ma__zhafu.name, 0)
    end
  end,
  on_use = function(self, event, target, player, data)
    player:drawCards(1, ma__zhafu.name)
  end,
})

return ma__zhafu